package CTRLayer;
import ModelLayer.*;
import DBLayer.*;
import java.util.ArrayList;


public class CtrProduct {

    public CtrProduct() {

    }

    
    
    public ArrayList<Product> getAllProducts()
    {
      IFDBProduct dbProd = new DBProduct();
      ArrayList<Product> allProd = new ArrayList();
      allProd = dbProd.getAllProducts(false);
      return allProd;
    }

    public Product findByName(String name) {
	IFDBProduct dbProd = new DBProduct();
	return dbProd.searchProductOnName(name, true);
    }

    public Product findByID(int productID)
    {
        IFDBProduct dbProd = new DBProduct();
        return dbProd.findProduct(productID, true);
    }

    public int updateProduct(int productID, String name, double purchasePrice, 
            double salesPrice, double rentPrice, String countryOfOrigin, int minStock, 
            double size, String color, String type, String description, 
            String fabric, double calibre, int supplierID)
    
    {
	
        IFDBProduct dbProd = new DBProduct();
	
        Product prod = new Product();
        
        prod.setProductID(productID);
	prod.setName(name);
	prod.setPurchasePrice(purchasePrice);
	prod.setSalesPrice(salesPrice);
	prod.setRentPrice(rentPrice);
	prod.setCountryOfOrigin(countryOfOrigin);
	prod.setMinStock(minStock);
        
        prod.setSupplierID(supplierID);
        
	return dbProd.updateProduct(prod);
    }
    
    public int insertProduct(Product pro) 
    {
	IFDBProduct dbPro = new DBProduct();
        return dbPro.insertProduct(pro);

     }
    
    public int deleteProduct(int id)
    {
        IFDBProduct dbPro = new DBProduct();
        return dbPro.deleteProduct(id);
    }


}
